import baseRequest from "@/utils/request";

/**
 * 重写request
 * @param config
 * @returns {Promise | Promise<unknown>}
 */
const request = function (config) {
  config.baseURL = process.env.VUE_APP_BASE_API + '/shippingPlan'
  return baseRequest(config)
}


/**
 * 获取添加发货信息的数据
 * @returns {Promise|Promise<*>}
 */
export function getAddPlanData(){
  return request({
    url: '/getAddPlanData',
  })
}


/**
 * 获取发货计划详情
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function getShippingPlanInfo(id){
  return request({
    url: `/getShippingPlanInfo/${id}`,
    handleError: true,
  })
}


/**
 * 修改发货计划
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function editShippingPlan(data){
  return request({
    url: '/editShippingPlan',
    data,
    method: 'put',
  })
}

/**
 * 获取发货计划列表
 * @param params
 * @returns {Promise|Promise<*>}
 */
export function getShippingPlanList(params = {}){
  return request({
    url: '/getShippingPlanList',
    params,
  })
}

/**
 * 修改发货计划的状态
 * @param data
 * @returns {Promise|Promise<*>}
 */
export function changeShippingPlan(data){
  return request({
    url: '/changeShippingPlan',
    data,
    method: 'patch',
    handleError: true,
  })
}

/**
 * 撤销计划
 * @param id
 * @returns {Promise|Promise<*>}
 */
export function deleteShippingPlan(id){
  return request({
    url: `/deleteShippingPlan/${id}`,
    method: 'delete',
    handleError: true,
  })
}
